﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace WH.NurseSys.Report
{
    public class ConfigHelper
    {
        public static void SetAppSetting(string key, string value)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (config.AppSettings.Settings[key] == null)
                config.AppSettings.Settings.Add(key, value);
            else
                config.AppSettings.Settings[key].Value = value;
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }

        public static void SetConnectionStr(string name, string value)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (config.ConnectionStrings.ConnectionStrings[name] == null)
                config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings(name,value));
            else
                config.ConnectionStrings.ConnectionStrings[name].ConnectionString = value;
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("connectionStrings");
        }
    }
}
